package com.ctgu.rabbitmq.rabbitmq.workQueue;

import lombok.extern.log4j.Log4j2;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

/**
 * @ ClassName WorkQueueConsumer
 * @ Author Alex2
 * @ Date 2025/8/23 16:12
 **/
@Log4j2
@Component
public class WorkQueueConsumer {

    private static final String TAG = "Alex-Consumer";

    @RabbitListener(
            queues = WorkQueueConfig.WORK_QUEUE,
            containerFactory = "workQueueListenerFactory"
    )
    public void receive(String msg) throws InterruptedException {
        String threadName = Thread.currentThread().getName();
        // 根据消息类型模拟耗时
        if (msg.startsWith("IMAGE_")) {
            Thread.sleep(1000); // 图片处理任务
        } else if (msg.startsWith("VIDEO_")) {
            Thread.sleep(10000); // 视频处理任务
        }

        log.info("线程[{}] 完成任务: {}", threadName, msg);
    }
}
